package com.gaofans.nrpc.server.bootstrap;

import com.gaofans.nrpc.common.compress.Codec;
import com.gaofans.nrpc.common.serializer.SerializerFactory;
import com.gaofans.nrpc.common.id.IdGenerator;
import io.netty.channel.ChannelOption;
import io.netty.handler.ssl.SslContext;

import java.util.HashMap;
import java.util.Map;

/**
 * @author GaoFans
 */
@SuppressWarnings("rawtypes")
public class ServerBootstrapConfig {

    /**
     * 进行请求分发的线程数
     */
    private int parentThreadCount;

    /**
     * 处理请求的线程数
     */
    private int childThreadCount;

    /**
     * 将请求分发到业务处理线程的线程数
     */
    private int workerThreadCount;

    /**
     * 具体处理业务的线程数
     */
    private int handlerThreadCount;

    /**
     * netty的相关配置
     */
    private final Map<ChannelOption, Object> optionMap = new HashMap<>();

    /**
     * 序列化工厂
     */
    private SerializerFactory serializerFactory;

    /**
     * 序列化类型
     */
    private byte serializerType;

    /**
     * 版本号
     */
    private short version;

    /**
     * 请求的编码器
     */
    private Codec codec;

    /**
     * 请求id生成器
     */
    private IdGenerator idGenerator;

    /**
     * 服务占用的端口
     */
    private int port;

    /**
     * 心跳的读超时时间
     */
    private int readerIdleTimeSecond = 30;

    /**
     * 心跳的写超时时间
     */
    private int writerIdleTimeSecond = 25;

    /**
     * 开启ssl连接所需的context，null则不开启
     */
    private SslContext sslContext;

    public int getParentThreadCount() {
        return parentThreadCount;
    }

    public void setParentThreadCount(int parentThreadCount) {
        this.parentThreadCount = parentThreadCount;
    }

    public int getChildThreadCount() {
        return childThreadCount;
    }

    public void setChildThreadCount(int childThreadCount) {
        this.childThreadCount = childThreadCount;
    }

    public int getWorkerThreadCount() {
        return workerThreadCount;
    }

    public void setWorkerThreadCount(int workerThreadCount) {
        this.workerThreadCount = workerThreadCount;
    }

    public int getHandlerThreadCount() {
        return handlerThreadCount;
    }

    public void setHandlerThreadCount(int handlerThreadCount) {
        this.handlerThreadCount = handlerThreadCount;
    }

    public SerializerFactory getSerializerFactory() {
        return serializerFactory;
    }

    public Map<ChannelOption, Object> getOptionMap() {
        return optionMap;
    }

    public void setOptionMap(ChannelOption key,Object value) {
        this.optionMap.put(key,value);
    }

    public void setSerializerFactory(SerializerFactory serializerFactory) {
        this.serializerFactory = serializerFactory;
    }

    public byte getSerializerType() {
        return serializerType;
    }

    public void setSerializerType(byte serializerType) {
        this.serializerType = serializerType;
    }

    public short getVersion() {
        return version;
    }

    public void setVersion(short version) {
        this.version = version;
    }

    public Codec getCodec() {
        return codec;
    }

    public void setCodec(Codec codec) {
        this.codec = codec;
    }

    public IdGenerator getIdGenerator() {
        return idGenerator;
    }

    public void setIdGenerator(IdGenerator idGenerator) {
        this.idGenerator = idGenerator;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public int getReaderIdleTimeSecond() {
        return readerIdleTimeSecond;
    }

    public void setReaderIdleTimeSecond(int readerIdleTimeSecond) {
        this.readerIdleTimeSecond = readerIdleTimeSecond;
    }

    public int getWriterIdleTimeSecond() {
        return writerIdleTimeSecond;
    }

    public void setWriterIdleTimeSecond(int writerIdleTimeSecond) {
        this.writerIdleTimeSecond = writerIdleTimeSecond;
    }

    public SslContext getSslContext() {
        return sslContext;
    }

    public void setSslContext(SslContext sslContext) {
        this.sslContext = sslContext;
    }
}
